home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / VIEWS.ZIP;1 / CVDZIP.EXE / CVDEMOVW.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-21  |  10.3 KB  |  461 lines

  1. /*
  2.     cvdemovw.cpp
  3.  
  4.     Main window for cvdemo
  5.  
  6.     C++/Views 2.0 Demo
  7.     Copyright (c) 1992, by Liant Software Corp.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12. */
  13.  
  14. #include "brush.h"
  15. #include "cvdemovw.h"
  16. #include "cvdialog.h"
  17. #include "cvintrvw.h"
  18. #include "font.h"
  19. #include "pen.h"
  20. #include "popupmen.h"
  21. #include "port.h"
  22. #include "cvclass.h"
  23. #include "cvfeatur.h"
  24. #include "cvsketch.h"
  25. #include "cvplatfm.h"
  26. #include "cvorder.h"
  27. #include "messengr.h"
  28. #include "toolbar.h"
  29. #include "picbttn.h"
  30. #include "textbox.h"
  31. #include "yesno.h"
  32. #include "cvabout.h"
  33. #include "cvhow.h"
  34.  
  35. #define    TOOL_HGT    28    // height of the ToolBar Window
  36. #define    STAT_HGT    0    // height of the Status Bar Window (if present)
  37. #define CLNT_HGT    380    // height of the MDI client window
  38. #define VIEW_HGT    (TOOL_HGT+CLNT_HGT+STAT_HGT)    // total height of the VMdiAppView
  39.  
  40. defineClass(DemoAppView, VMdiAppView)
  41.  
  42. /* menu definition */
  43.  
  44. char *filechoices[]    = {    "E&xit",
  45.                         0 };
  46.  
  47. method filemthds[] = {    methodOf(DemoAppView, menuExit),
  48.                         NIL_METHOD };
  49.  
  50. char *featurechoices[]    = {    "&Introduction",
  51.                         "&Classes",
  52.                         "&Features",
  53.                         "&Platforms",
  54.                         0 };
  55.  
  56. method featuremthds[] = { methodOf(DemoAppView, menuIntro),
  57.                         methodOf(DemoAppView, menuClass),
  58.                         methodOf(DemoAppView, menuFeature),
  59.                         methodOf(DemoAppView, menuPlatform),
  60.                         NIL_METHOD };
  61.  
  62. char *examplechoices[]    = {    "&Dialog...",
  63.                             "&Sketch Pad",
  64.                             0 };
  65.  
  66. method examplemthds[] = { methodOf(DemoAppView, menuDialog),
  67.                         methodOf(DemoAppView, menuSketch),
  68.                         NIL_METHOD };
  69.  
  70. char *aboutchoices[]    = {    "About this &Demo...",
  71.                             "About the Current &Window...",
  72.                             "About &Ordering C++/Views...",
  73.                             0 };
  74.  
  75. method aboutmthds[] = { methodOf(DemoAppView, menuAbout),
  76.                         methodOf(DemoAppView, menuAboutCurrWin),
  77.                         methodOf(DemoAppView, menuOrder),
  78.                         NIL_METHOD };
  79.  
  80. /* bitmaps for toolbar buttons */
  81. char *pix_class[] =        {"BTNCLSUP", "BTNCLSDN", 0, 0 };
  82. char *pix_dialog[] =    {"BTNDLGUP", "BTNDLGDN", 0, 0 };
  83. char *pix_feature[] =    {"BTNFTRUP", "BTNFTRDN", 0, 0 };
  84. char *pix_intro[] =        {"BTNCPPUP", "BTNCPPDN", 0, 0 };
  85. char *pix_order[] =        {"BTNORDUP", "BTNORDDN", 0, 0 };
  86. char *pix_platform[] =    {"BTNPLTUP", "BTNPLTDN", 0, 0 };
  87. char *pix_sketch[] =    {"BTNSKHUP", "BTNSKHDN", 0, 0 };
  88. char *pix_how[] =        {"BTNHOWUP", "BTNHOWDN", 0, 0 };
  89.  
  90. /* the message dispatcher object */
  91. Messenger *cvTextFile;
  92.  
  93. DemoAppView::DemoAppView()
  94.     :    VMdiAppView(VFrame(20, 20, 500, VIEW_HGT), VFrame(0, TOOL_HGT, 1.0F, CLNT_HGT), StyleDefault),
  95.          aboutTopic("Intro:About"),
  96.         aboutSource("cvdemovw.cpp")
  97. {
  98.     init();
  99.     initWindow();
  100.  
  101.     /* open demo text file for messages */
  102.     cvTextFile = new Messenger("cvdemo.txt");
  103.  
  104.     /* force messager to find last message in file */
  105.     /* (this will make subsequent calls to the messager faster) */
  106.     cvTextFile->getMessage("ZZZ:lastmsg");
  107.  
  108.     /* popup intro window */
  109.     menuIntro(0);
  110. }
  111.  
  112. DemoAppView::~DemoAppView()
  113. {
  114.     /* destroy background brush (if present) */
  115.     delete getBackground();
  116.  
  117.     delete toolBrush;
  118.     delete toolFont;
  119. }
  120.  
  121. boolean DemoAppView::free()
  122. {
  123.     delete this;
  124.     return(TRUE);
  125. }
  126.  
  127. void DemoAppView::init()
  128. /*
  129.     Initialize class variables
  130. */
  131. {
  132.     visitFlag = 0;
  133.     tools = 0;
  134.  
  135.     classView = 0;
  136.     featureView = 0;
  137.     introView = 0;
  138.     platformView = 0;
  139.     sketchView = 0;
  140.  
  141.     toolBrush = 0;
  142.     toolFont = 0;
  143. }
  144.  
  145. void DemoAppView::initWindow()
  146. /*
  147.     Create main menu & tool bar.
  148. */
  149. {
  150.     /* set title and background brush for main window */
  151.     setTitle("C++/Views 2.0");
  152.     setBackground(new VBrush(BLUE));
  153.  
  154.     /* get the size of the window */
  155.     int x, y, w, h;
  156.     getArea(&x, &y, &w, &h);
  157.  
  158.     /* create the tool bar */
  159.     tools = new ToolBar(VFrame(0, 0, 1.0F, TOOL_HGT), this);
  160.  
  161.     /* create buttons within the tool bar */
  162.     VPicButton *pb;
  163.  
  164.     pb = new VPicButton(  5, 3, pix_class, tools);
  165.     pb->uponClick(this, methodOf(DemoAppView, menuClass));
  166.  
  167.     pb = new VPicButton( 35, 3, pix_feature, tools);
  168.     pb->uponClick(this, methodOf(DemoAppView, menuFeature));
  169.  
  170.     pb = new VPicButton( 65, 3, pix_platform, tools);
  171.     pb->uponClick(this, methodOf(DemoAppView, menuPlatform));
  172.  
  173.     pb = new VPicButton( 95, 3, pix_dialog, tools);
  174.     pb->uponClick(this, methodOf(DemoAppView, menuDialog));
  175.  
  176.     pb = new VPicButton(125, 3, pix_order, tools);
  177.     pb->uponClick(this, methodOf(DemoAppView, menuOrder));
  178.  
  179.     pb = new VPicButton(155, 3, pix_sketch, tools);
  180.     pb->uponClick(this, methodOf(DemoAppView, menuSketch));
  181.  
  182.     pb = new VPicButton(185, 3, pix_intro, tools);
  183.     pb->uponClick(this, methodOf(DemoAppView, menuIntro));
  184.  
  185.     pb = new VPicButton(215, 3, pix_how, tools);
  186.     pb->uponClick(this, methodOf(DemoAppView, menuAboutCurrWin));
  187.  
  188.     toolBrush = new VBrush(LightGray);
  189.     toolFont = new VFont("TMS RMN", 10);
  190.  
  191.     /* create the pull down menu (using arrays defined above) */
  192.     fileMenu = new VPopupMenu("&File");
  193.     addPopup(fileMenu);
  194.     fileMenu->addItems(filechoices, filemthds, this);
  195.  
  196.     featureMenu = new VPopupMenu("Fea&tures");
  197.     addPopup(featureMenu);
  198.     featureMenu->addItems(featurechoices, featuremthds, this);
  199.  
  200.     exampleMenu = new VPopupMenu("&Examples");
  201.     addPopup(exampleMenu);
  202.     exampleMenu->addItems(examplechoices, examplemthds, this);
  203.  
  204.     VPopupMenu       *aboutMenu;
  205.     aboutMenu = new VPopupMenu("&About");
  206.     addPopup(aboutMenu);
  207.     aboutMenu->addItems(aboutchoices, aboutmthds, this);
  208.  
  209.     /* Put up "Window" menu. */
  210.     addPopup((id)mdiPopup());
  211. }
  212.  
  213. boolean DemoAppView::close()
  214. /*
  215.     The user wants to quit--ask if it's ok.
  216. */
  217. {
  218.     return(!okToQuit());
  219. }
  220.  
  221. boolean DemoAppView::resized(int w, int h) 
  222. /*
  223.     This function is called whenever our window changes size.
  224. */
  225. {
  226.     /* resize the toolbar */
  227.     if (tools) {
  228.         tools->resize(w, TOOL_HGT);
  229.     }
  230.  
  231.     /* resize the MDI client area */
  232.     client.resize(w, h - (TOOL_HGT + STAT_HGT));
  233.  
  234.     return(TRUE);
  235. }
  236.  
  237. void DemoAppView::updateMenu()
  238. /*
  239.     Update menu bar check marks
  240. */
  241. {
  242.     featureMenu->checkAt((introView != 0), 0);
  243.     featureMenu->checkAt((classView != 0), 1);
  244.     featureMenu->checkAt((featureView != 0), 2);
  245.     featureMenu->checkAt((platformView != 0), 3);
  246.  
  247.     exampleMenu->checkAt((sketchView != 0), 2);
  248. }
  249.  
  250. void DemoAppView::setAboutNames(char *tpc, char *src)
  251. /*
  252.     Set topic and source names for the About Curr Win box.
  253. */
  254. {
  255.     aboutTopic.puts(tpc);
  256.     aboutSource.puts(src);
  257. }
  258.  
  259. /* Menu Bar Callbacks */
  260.  
  261. boolean DemoAppView::menuClass(VMenuItem *m)
  262. /*
  263.     Feature-Class pulldown: give class info
  264. */
  265. {
  266.     if (!classView) {
  267.         classView = new ClassView(VFrame(0, 0, 500, 350), this);
  268.         classView->bringToTop();
  269.         visitFlag |= VISIT_CLASS;
  270.     }
  271.     else {
  272.         classView->free();
  273.         classView = 0;
  274.     }
  275.  
  276.     updateMenu();
  277.     return(TRUE);
  278. }
  279.  
  280. boolean DemoAppView::menuPlatform(VMenuItem *m)
  281. /*
  282.     Feature-Platform pulldown: give platform info
  283. */
  284. {
  285.     if (!platformView) {
  286.         platformView = new PlatformView(VFrame(50, 50, 300, 300), this);
  287.         platformView->bringToTop();
  288.         visitFlag |= VISIT_PLATFORM;
  289.     }
  290.     else {
  291.         platformView->free();
  292.         platformView = 0;
  293.     }
  294.  
  295.     updateMenu();
  296.     return(TRUE);
  297. }
  298.  
  299. boolean DemoAppView::menuIntro(VMenuItem *m)
  300. /*
  301.     Feature-Intro pulldown: give Views intro
  302. */
  303. {
  304.     if (!introView) {
  305.         introView = new IntroView(VFrame(0.5F, 0.5F, 0.9F, 0.9F, CenterDim), this);
  306.         introView->bringToTop();
  307.     }
  308.     else {
  309.         introView->free();
  310.         introView = 0;
  311.     }
  312.  
  313.     updateMenu();
  314.     return(TRUE);
  315. }
  316.  
  317. boolean DemoAppView::menuFeature(VMenuItem *m)
  318. /*
  319.     Feature-Feature pulldown: give list of features
  320. */
  321. {
  322.     if (!featureView) {
  323.         featureView = new FeatureView(VFrame(20, 50, 500, 200), this);
  324.         featureView->bringToTop();
  325.         visitFlag |= VISIT_FEATURE;
  326.     }
  327.     else {
  328.         featureView->free();
  329.         featureView = 0;
  330.     }
  331.  
  332.     updateMenu();
  333.     return(TRUE);
  334. }
  335.  
  336. boolean DemoAppView::menuOrder(VMenuItem *m)
  337. /*
  338.     Feature-Order pulldown: present how-to-order dialog
  339. */
  340. {
  341.     OrderDialog order(this);
  342.     order.modal();
  343.     return(TRUE);
  344. }
  345.  
  346. boolean DemoAppView::menuDialog(VMenuItem *m)
  347. /*
  348.     Example-Dialog pulldown: give dialog example
  349. */
  350. {
  351.     DialogView dlg(this);
  352.  
  353.     dlg.modal();
  354.  
  355.     visitFlag |= VISIT_DIALOG;
  356.     return(TRUE);
  357. }
  358.  
  359. boolean DemoAppView::menuSketch(VMenuItem *m)
  360. /*
  361.     Example-Sketch pulldown: sketchpad world example
  362. */
  363. {
  364.     if (!sketchView) {
  365.         sketchView = new SketchView(VFrame(50, 50, 300, 250), this);
  366.         sketchView->bringToTop();
  367.         visitFlag |= VISIT_SKETCH;
  368.     }
  369.     else {
  370.         sketchView->free();
  371.         sketchView = 0;
  372.     }
  373.  
  374.     updateMenu();
  375.     return(TRUE);
  376. }
  377.  
  378. boolean DemoAppView::menuAbout(VMenuItem *m)
  379. /*
  380.     File-About: Display the About box
  381. */
  382. {
  383.     BounceAbout    b(this);
  384.  
  385.     /* make the about dialog visible */
  386.     b.show();
  387.  
  388.     /* activate the about dialog (as a modal dialog) */
  389.     b.modal();
  390.  
  391.     visitFlag |= VISIT_ABOUT;
  392.     return(TRUE);
  393. }
  394.  
  395. boolean DemoAppView::menuAboutCurrWin(VMenuItem *m)
  396. /*
  397.     File-AboutCurrWin: Display the How-it-works box for the current window
  398. */
  399. {
  400.     HowView    how(this, aboutTopic.gets(), aboutSource.gets());
  401.  
  402.     /* make the about how visible */
  403.     how.show();
  404.  
  405.     /* activate the dialog (as a modal dialog) */
  406.     how.modal();
  407.  
  408.     return(TRUE);
  409. }
  410.  
  411. boolean DemoAppView::menuExit(VMenuItem *m)
  412. /*
  413.     File-Exit: Close the application
  414. */
  415. {
  416.     if (okToQuit()) {
  417.         return(VAppView::close());
  418.     }
  419.  
  420.     return(TRUE);
  421. }
  422.  
  423. boolean DemoAppView::okToQuit(void)
  424. /*
  425.     Ask the user if she really wants to quit.
  426.     Returns TRUE if the user says OK.
  427.     Use visitFlag to choose from a selection of cute messages.
  428. */
  429. {
  430.     char *msg = "Do you wish to leave the C++/Views demo?";
  431.  
  432.     if (!(visitFlag & VISIT_CLASS)) {
  433.         msg = "Leaving so soon?\nYou haven't seen the class hierarchy demo.";
  434.         visitFlag |= VISIT_CLASS;
  435.     }
  436.     else if (!(visitFlag & VISIT_FEATURE)) {
  437.         msg = "Are you sure you want to exit?\nYou haven't looked at the feature list yet.";
  438.         visitFlag |= VISIT_FEATURE;
  439.     }
  440.     else if (!(visitFlag & VISIT_PLATFORM)) {
  441.         msg = "Going already?\nBut I spent so much time on the list of supported platforms.";
  442.         visitFlag |= VISIT_PLATFORM;
  443.     }
  444.     else if (!(visitFlag & VISIT_DIALOG)) {
  445.         msg = "What's the rush?\nYou didn't try out the Example Dialog.";
  446.         visitFlag |= VISIT_DIALOG;
  447.     }
  448.     else if (!(visitFlag & VISIT_SKETCH)) {
  449.         msg = "Are you sure you want to exit?\nYou never saw the Sketch Pad example.";
  450.         visitFlag |= VISIT_SKETCH;
  451.     }
  452.     else if (!(visitFlag & VISIT_ABOUT)) {
  453.         msg = "Wait a minute!\nYou forgot to check out the About box.";
  454.         visitFlag |= VISIT_ABOUT;
  455.     }
  456.     
  457.     return(VYesNo::question(FALSE, YesButton, "Exit C++/Views Demo", this, msg) == YesButton);
  458. }
  459.  
  460.  
  461.